<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>底部导航栏原型</title>
    <style>
        /* 全局样式 */
        html,
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
                         "PingFang SC", "Hiragino Sans GB",
                         "Microsoft YaHei", sans-serif;
            background-color: #faf9f5;
            color: #333333;
            font-size: 14px;
            line-height: 1.4;
            height: 100%;
            margin: 0;
            padding: 0;
        }

        /* 页面容器 */
        .container {
            max-width: 480px;
            margin: 0 auto;
            background-color: #f5f5f6;
            min-height: 100%;
            position: relative;
            overflow: hidden;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }

        /* ===== TabBar 样式 ===== */
        .bottomNav {
            width: 100%;
            background-color: #ffffff;
            padding: 8px 0;
            display: flex;
            justify-content: space-around;
            align-items: center;
            z-index: 101;
        }

        .navItem {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 4px;
            padding: 8px;
            color: #999999;
            cursor: pointer;
            transition: color 0.3s ease;
            text-align: center;
            text-decoration: none;
        }

        .navItem.active {
            color: #333333;
            font-weight: 500;
        }

        .navIcon {
            width: 24px;
            height: 24px;
            border-radius: 4px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 9px;
            font-weight: 500;
            background-color: #e8e8e8;
        }

        .navLabel {
            font-size: 11px;
        }
    </style>
</head>
<body>
    <div class="container">
        <!-- 底部导航栏 -->
        <div class="bottomNav" id="tabBar">
            <a href="#" class="navItem" data-tab="home">
                <div class="navIcon">首</div>
                <div class="navLabel">首页</div>
            </a>
            <a href="#" class="navItem" data-tab="game">
                <div class="navIcon">球</div>
                <div class="navLabel">球局</div>
            </a>
            <a href="#" class="navItem" data-tab="venue">
                <div class="navIcon">馆</div>
                <div class="navLabel">球馆</div>
            </a>
            <a href="#" class="navItem" data-tab="profile">
                <div class="navIcon">我</div>
                <div class="navLabel">我的</div>
            </a>
        </div>
    </div>

    <script>
        /**
         * TabBar 组件
         * 用于管理底部导航栏的样式和交互
         */
        class TabBar {
            constructor() {
                this.tabBar = document.getElementById('tabBar');
                this.navItems = this.tabBar.querySelectorAll('.navItem');
                this.initEventListeners();
            }

            /**
             * 初始化事件监听器
             */
            initEventListeners() {
                this.navItems.forEach(item => {
                    item.addEventListener('click', (e) => {
                        e.preventDefault();
                        const tabName = item.getAttribute('data-tab');
                        this.setActiveTab(tabName);
                    });
                });
            }

            /**
             * 设置活跃的标签页
             * @param {string} tabName - 标签名称
             */
            setActiveTab(tabName) {
                // 移除所有 active 类
                this.navItems.forEach(item => {
                    item.classList.remove('active');
                });

                // 添加 active 类到目标标签
                const activeItem = this.tabBar.querySelector(`[data-tab="${tabName}"]`);
                if (activeItem) {
                    activeItem.classList.add('active');
                }

                // 触发自定义事件，供其他页面使用
                const event = new CustomEvent('tabChanged', {
                    detail: { tabName }
                });
                document.dispatchEvent(event);
            }

            /**
             * 获取当前活跃的标签页名称
             * @returns {string} 标签名称
             */
            getActiveTab() {
                const activeItem = this.tabBar.querySelector('.navItem.active');
                return activeItem ? activeItem.getAttribute('data-tab') : null;
            }
        }

        // 初始化 TabBar
        const tabBar = new TabBar();

        // 暴露到全局作用域，供其他页面使用
        window.TabBar = tabBar;
    </script>
</body>
</html>
